package com.iot.broker.mvc.mqtt.controller;

import javax.annotation.Resource;
import org.apache.activemq.artemis.jms.client.ActiveMQTopic;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.iot.common.core.util.R;

import lombok.RequiredArgsConstructor;

@RestController
@RequiredArgsConstructor
@RequestMapping("/topic")
public class TopicController {

	@Resource
	private JmsTemplate jmsTemplate;

	@PostMapping(value = { "/send" }, produces = "application/json; charset=utf-8")
	public R<String> send(@RequestParam(name = "topic", required = true) String topic,
			@RequestParam(name = "payload", required = false) String payload) {
		jmsTemplate.convertAndSend(new ActiveMQTopic(topic), payload);
		return R.ok();
	}

}
